import { init as initGlobal } from "@common/events";
import { makeActions, eventHub } from "@common/utils/eventActionsMaker";

const events = {
  Test: makeActions("test"),

  Remote: {
    Invoke: makeActions<{
      eventName: string;
      data: unknown;
      receiverId: "ui" | "plugin";
    }>("remote.invoke"),
    Accept: (() => {
      const { on, off, emit } = makeActions<{
        eventName: string;
        data: unknown;
        sender: string;
      }>("remote.accept");
      return { on, off, emit };
    })(),
  },

  Global: initGlobal({ makeActions }),
};

events.Remote.Accept.on(({ eventName, sender, data }) => {
  eventHub.emit(eventName, data, eventName, sender);
});

export default events;
